package com.copa.l705;

import java.util.ArrayList;

/**
 * @author copa
 * @createDate 2022-06-13 11:13
 * @function ArrayList api
 */
public class Test1 {

    private ArrayList<Integer> list;

    public Test1() {
        this.list = new ArrayList<>();
    }

    public void add(int key) {
        for (Integer num : list) {
            if (num == key) {
                return;
            }
        }
        list.add(key);
    }

    public void remove(int key) {
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) == key) {
                list.remove(i);
                return;
            }
        }
    }

    public boolean contains(int key) {
        return list.contains(key) ? true : false;
    }

    public static void main(String[] args) {
        Test1 myHashSet = new Test1();
        myHashSet.add(1);      // set = [1]
        myHashSet.add(2);      // set = [1, 2]
        myHashSet.contains(1); // 返回 True
        myHashSet.contains(3); // 返回 False ，（未找到）
        myHashSet.add(2);      // set = [1, 2]
        myHashSet.contains(2); // 返回 True
        myHashSet.remove(2);   // set = [1]
        myHashSet.contains(2); // 返回 False ，（已移除）
    }
}
